import qs from "qs";
import Vue from "vue";
import App from "./App.vue";
import router from "./router";
import store from "./store";
import ElementUI from "element-ui";
import "element-ui/lib/theme-chalk/index.css";
//  引入 Vant  ui组件库
import Vant from "vant";
import "vant/lib/index.css";
//  引入 全局样式
import "@/styles/index.scss";
import "./assets/iconfont/iconfont.css";
import "./assets/iconfont/iconfont.js";
import axios from "./utils/request";

// 路由守卫
// const originalPush = Router.prototype.push
// Router.prototype.push = function push(location, onResolve, onReject) {
//   if (onResolve || onReject) return originalPush.call(this, location, onResolve, onReject)
//   return originalPush.call(this, location).catch((err) => err)
// }

const whiteList = ["/login"]; 
router.beforeEach((to, from, next) => {
  const token = localStorage.getItem("EMEStoken");
  if (token) {
    next();
  } else {
    if (whiteList.indexOf(to.path) !== -1) {
      next();
    } else {
      next(`/login?redirect=${to.path}`);
    }
  }
});

Vue.use(ElementUI);
Vue.use(Vant);
Vue.prototype.$axios = axios;
Vue.prototype.$qs = qs;
Vue.config.productionTip = false;
// 阻止多次点击重复提交
Vue.directive("noMoreClick", {
  inserted(el, binding) {
    el.addEventListener("click", (e) => {
      el.classList.add("is-disabled");
      el.disabled = true;
      setTimeout(() => {
        el.disabled = false;
        el.classList.remove("is-disabled");
      }, 1500);
    });
  },
});
new Vue({
  router,
  store,
  render: (h) => h(App),
}).$mount("#app");
